$(function () {

    //变量抽取
    var loss_dataGrid = $("#loss_dataGrid");
    var loss_dialog = $("#loss_dialog");
    var loss_form = $("#loss_form");

    //页面数据列表
    loss_dataGrid.datagrid({
        url: "/lossRecord/query.do",
        fitColumns: true,//列自适应
        fit: true,
        align: 'center',
        queryParams:{
            state:'-2'
        },
        columns: [[
            {field: 'id', title: '编号', width: 100, align: 'center'},
            {
                field: 'lossDate', title: '时间', width: 100, align: 'center'
            },
            {
                field: 'clientName', title: '客户', width: 100, align: 'center'
            },
            {
                field: 'chargeEmp', title: '负责人', width: 100, align: 'center'
            },
            {field: 'remark', title: '详细原因', width: 100, align: 'center'},
        ]],
        toolbar: "#tb",//工具
        pagination: true,//分页
        rownumbers: true,//行号
        singleSelect: true//只允许选择一行
    });

    //方法抽成对象统一管理
    var methodObj = {

        //刷新按钮
        reload: function () {
            //清空查询条件
            $("#beginDate").textbox("setValue",'');
            $("#endDate").textbox("setValue",'');
            $("#clientName").textbox("setValue",'');
            $("#chargeEmp").textbox("setValue",'');
            loss_dataGrid.datagrid("load",{
                state: -2
            });
        },

        //查询按钮
        searchForm:function () {
            //获取输入框的内容
            var beginDate = $("[name=beginDate]").val();
            var endDate = $("[name=endDate]").val();
            var clientName = $("[name=clientName]").val();
            var chargeEmp = $("[name=chargeEmp]").val();

            loss_dataGrid.datagrid('load', {
                beginDate: beginDate,
                endDate: endDate,
                clientName: clientName,
                chargeEmp: chargeEmp,
                state: -2
            });
        }
    };

    //按钮统一绑定事件
    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd]();
    });

});


